using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 字段定义实体
    /// 用于定义内容模型中的字段结构和属性
    /// </summary>
    [Table("cms_fields")]
    public class Field : ITenantEntity
    {
        /// <summary>
        /// 字段标识符
        /// </summary>
        public long Id { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }
        
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }
        
        /// <summary>
        /// 字段名称
        /// 字段的名称标识
        /// </summary>
        [Required]
        [MaxLength(100)]
        public string Name { get; set; } = string.Empty;
        
        /// <summary>
        /// 字段类型
        /// 如：文本、数字、日期、布尔值、文件等
        /// </summary>
        [Required]
        [MaxLength(50)]
        public string Type { get; set; } = string.Empty;
        
        /// <summary>
        /// 字段标签
        /// 用户友好的字段显示名称
        /// </summary>
        [MaxLength(200)]
        public string? Label { get; set; }
        
        /// <summary>
        /// 字段描述
        /// 对字段用途和内容的详细说明
        /// </summary>
        [MaxLength(500)]
        public string? Description { get; set; }
        
        /// <summary>
        /// 是否必填
        /// 标识该字段是否为必填字段
        /// </summary>
        public bool IsRequired { get; set; } = false;
        
        /// <summary>
        /// 默认值
        /// 字段的默认值
        /// </summary>
        [MaxLength(500)]
        public string? DefaultValue { get; set; }
        
        /// <summary>
        /// 字段选项
        /// JSON格式存储字段的配置选项
        /// </summary>
        [Column(TypeName = "json")]
        public string? Options { get; set; }
        
        /// <summary>
        /// 验证规则
        /// JSON格式存储字段的验证规则
        /// </summary>
        [Column(TypeName = "json")]
        public string? ValidationRules { get; set; }
        
        /// <summary>
        /// 所属内容模型ID
        /// </summary>
        public long ContentModelId { get; set; }
        
        /// <summary>
        /// 所属内容模型
        /// </summary>
        [ForeignKey(nameof(ContentModelId))]
        public virtual ContentModel? ContentModel { get; set; }
        
        /// <summary>
        /// 排序顺序
        /// 字段在表单或列表中的显示顺序
        /// </summary>
        public int Order { get; set; } = 0;
        
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsActive { get; set; } = true;

        /// <summary>
        /// 租户标识符
        /// </summary>
        public string TenantId { get; set; } = string.Empty;
    }
}
